#！/bin/bash
source /etc/profile
# 可以输入日期；如果未输入日期取昨天的时间
if [ -n "$1" ]
then
do_date=$1
else
do_date=`date -d "-1 day" +%F`
fi
# 定义要执行的SQL
# 汇总近三天的登录标记
sql="
select device_id, dt, Today, Yesterday, TheDayBeforeYesterday from
(select device_id, dt, 
case when dt = '$do_date' then 1 else 0 end as Today, 
case when dt = date_add('$do_date', - 1) then 1 else 0 end as Yesterday,
case when dt = date_add('$do_date', - 2) then 1 else 0 end as TheDayBeforeYesterday  
from dws.dws_member_start_day) t
;
"
hive -e "$sql"

